import { Form, Button, Col, Row, Input, Select, message } from 'antd';
import React, { Component } from 'react';
import { Employeeadd } from '../../../services/auth';
const { Option } = Select;

export default class CreateEmployee extends Component {
	constructor(props) {
		super(props);
		const { handleCreateClick } = this.props;
		this.handleCreateClick = handleCreateClick;
	}
	formRef = React.createRef();
	onFinish = (values) => {
		Employeeadd(values).then(
			(response) => {
				if (response.data.result === 'success') {
					message.success('账号' + response.data.employee_id + '已创建成功');
					this.formRef.current.resetFields();
					this.handleCreateClick();
				} else {
					message.info('提交失败，请重试');
				}
			},
			(error) => {
				console.log('数据获取失败', error);
			}
		);
	};

	render() {
		return (
			<Form layout="vertical" hideRequiredMark onFinish={this.onFinish} ref={this.formRef}>
				<Row gutter={24}>
					<Col span={12}>
						<Form.Item name="name" label="姓名" rules={[ { required: true, message: '请输入姓名' } ]}>
							<Input placeholder="必填项" />
						</Form.Item>
					</Col>
					<Col span={12}>
						<Form.Item name="authority" label="部门权限" rules={[ { required: true, message: '请选择部门' } ]}>
							<Select placeholder="必选项">
								<Option value="all">总管</Option>
								<Option value="admin">人事部</Option>
								<Option value="goods">产品部</Option>
								<Option value="order">销售部</Option>
								<Option value="stock">仓储部</Option>
								<Option value="delivery">物流部</Option>
								<Option value="finance">财务部</Option>
							</Select>
						</Form.Item>
					</Col>
				</Row>
				<Row gutter={24}>
					<Col span={12}>
						<Form.Item name="phone" label="电话">
							<Input placeholder="可选项" />
						</Form.Item>
					</Col>
					<Col span={12}>
						<Form.Item name="email" label="邮箱">
							<Input placeholder="可选项" />
						</Form.Item>
					</Col>
				</Row>
				<Row gutter={24} />

				<Form.Item>
					<div
						style={{
							textAlign: 'right'
						}}
					>
						<Button htmlType="reset" style={{ marginRight: 8 }}>
							重置
						</Button>
						<Button type="primary" htmlType="submit">
							提交
						</Button>
					</div>
				</Form.Item>
			</Form>
		);
	}
}
